﻿Imports CalificadorPremiosOscarDAL.pcs.dao

Namespace pcs.dao
    Public Class CategoriaDAO
        Inherits DAOBase

        Public Function ObtenerCategorias() As System.Linq.IQueryable(Of Categoria)
            Return (From r In Entitie.Categoria Order By r.id_categoria Ascending Select r)
        End Function

        Public Function ObtenerCategoriasGridView() As System.Linq.IQueryable(Of Object)
            Return From r In Entitie.Categoria Order By r.id_categoria Ascending
                   Select New With {
                        .id_Categoria = r.id_categoria,
                        .nombre_categoria = r.nombre_categoria,
                        .descripcion_categoria = r.descripcion_categoria
                       }
        End Function

        Public Function ObtenerCategorias(ByVal id_categoria As String) As System.Linq.IQueryable(Of Categoria)
            Return (From r In Entitie.Categoria Where r.id_categoria.Contains(id_categoria) Order By r.id_categoria Ascending Select r)
        End Function

        Public Function ObtenerCategoriasGridView(ByVal id_categoria As String) As System.Linq.IQueryable(Of Object)
            Return From r In Entitie.Categoria Where r.id_categoria.Contains(id_categoria) Order By r.id_categoria Ascending
                   Select New With {
                        .id_Categoria = r.id_categoria,
                        .nombre_categoria = r.nombre_categoria,
                        .descripcion_categoria = r.descripcion_categoria
                       }
        End Function


        Public Function ObtenerCategoria(ByVal id_categoria As String) As Categoria
            Return (From r In Entitie.Categoria Where r.id_categoria = id_categoria Select r).FirstOrDefault()
        End Function

        Public Sub AgregarCategoria(ByVal Categoria As Categoria)
            Entitie.Categoria.AddObject(Categoria)
            Try
                Entitie.SaveChanges()
            Catch ex As Exception
                Throw ex
            End Try
        End Sub

        Public Sub ModificarCategoria(ByVal categoria As Categoria)
            Try
                Dim cer As Categoria = (From r In Entitie.Categoria Where r.id_categoria = Categoria.id_categoria Select r).FirstOrDefault()
                cer.id_categoria = categoria.id_categoria
                cer.nombre_categoria = categoria.nombre_categoria
                cer.descripcion_categoria = categoria.descripcion_categoria
                Entitie.SaveChanges()
            Catch ex As Exception
                Throw ex
            End Try
        End Sub

        Public Sub EliminarCategoria(ByVal Categoria As Categoria)
            Dim temp As Categoria = (From r In Entitie.Categoria Where r.id_categoria = Categoria.id_categoria Select r).FirstOrDefault()
            Entitie.Categoria.DeleteObject(temp)
            Try
                Entitie.SaveChanges()
            Catch ex As Exception
                Throw ex
            End Try
        End Sub

    End Class
End Namespace
